package get.newsdaily;

import get.newsdaily.utils.variables;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.webkit.WebView;

public class NewsActivity extends Activity {
	private WebView webview;
	private String link;
	private ProgressDialog dialog;

	@SuppressLint("SetJavaScriptEnabled")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.article);
		
		
		Bundle bundle = getIntent().getExtras();
		setTitle(R.string.app_name);
		link = bundle.getString(variables.LINK);
		webview = (WebView) findViewById(R.id.webView);
		
		//fix frame beginwebView.setWebChromeClient(new WebChromeClient());
		webview.getSettings().setSupportZoom(true);
		webview.setInitialScale(1);
		webview.getSettings().setJavaScriptEnabled(true);
		webview.getSettings().setLoadWithOverviewMode(true);
		webview.getSettings().setUseWideViewPort(true);
		webview.setWebViewClient(new WebViewClient());
		webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
		webview.setScrollbarFadingEnabled(false);
		//fix frame end
		
		webview.setWebViewClient(new WebViewClient());
		dialog = ProgressDialog.show( this , "", "Loading...");
		new NewsTask().execute(); //begin Task
		
		
		
	}

	class NewsTask extends AsyncTask<Void, Void, Void>{

		@Override
		protected Void doInBackground(Void... params) {
			webview.loadUrl(link);
			return null;
		}

		
		
		
		
	}
	
	class WebViewClient extends android.webkit.WebViewClient {

		@Override
		public void onPageFinished(WebView view, String url) {
			if (dialog != null){
				dialog.dismiss(); // Drop dialog
			}
			super.onPageFinished(view, url);
		}
		
	}
	
}
